/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.classdiagram.parsers.texteditor.parameterlabel;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

import com.cea.papyrus.classdiagram.parsers.texteditor.ILabelColorConstants;
import com.cea.papyrus.classdiagram.parsers.texteditor.LabelColorProvider;
import com.cea.papyrus.classdiagram.parsers.texteditor.WhitespaceDetector;
import com.cea.papyrus.classdiagram.parsers.texteditor.completionproposals.ParameterModifierProposal;
import com.cea.papyrus.classdiagram.parsers.texteditor.completionproposals.VisibilityCompletionProposal;


/**
 * Scanner for the action language.<BR>
 * It implements the interface IALKeywords, which contains the different
 * keywords available in the action language
 * 
 * @author Remi SCHNEKENBURGER
 * @see org.eclipse.jface.text.rules.RuleBasedScanner
 * @see com.cea.actionlanguage.sharedresources.texteditor.IRTActionKeywords
 */
public class ParameterLabelScanner extends RuleBasedScanner implements ILabelColorConstants {

    // Color for the default token
    /**
     * 
     */
    private Color defaultColor;
    
    // Color for keywords
    /**
     * 
     */
    private Color keywordColor;
    
    // Color for special chars
    /**
     * 
     */
    private Color symbolColor;
    
    
	/**
	 * Creates a new rule based scanner.
	 */
	public ParameterLabelScanner() {
		defaultColor = LabelColorProvider.getDefault().getColor(DEFAULT);
		keywordColor = LabelColorProvider.getDefault().getColor(KEYWORD);
		symbolColor = LabelColorProvider.getDefault().getColor(SYMBOL);

		IToken other = new Token(new TextAttribute(defaultColor));
		IToken keyword = new Token(new TextAttribute(keywordColor, null, SWT.BOLD));
		IToken symbol = new Token(new TextAttribute(symbolColor, null, SWT.BOLD));
		
		IRule[] rules = new IRule[2];

		WordRule wordRule = new WordRule(new ParameterWordDetector(), other);
		for (int i = 0; i < VisibilityCompletionProposal.visibilityStrings.length; i++) {
			// wordRule.addWord(getWordWithoutQuotes(visibilityStrings[i]), keyword);
		}
		for (int i = 0; i < ParameterModifierProposal.modifiersStrings.length; i++) {
			wordRule.addWord(ParameterModifierProposal.modifiersStrings[i], keyword);
		}

		wordRule.addWord(":", symbol);
		
		
		
		rules[0] = wordRule;
		rules[1] = new WhitespaceRule(new WhitespaceDetector());
		

		setRules(rules);
	}
	
	/**
	 * returns the word for the scanner, without quotes.
	 * 
	 * @param word 
	 * 
	 * @return 
	 */
	public static String getWordWithoutQuotes(String word) {
	    String tmp="";
	    tmp = word.replaceAll("'", "");
	    return tmp;
	}
}